home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include "OverviewDay.h"
- #include "VCal.h"
- #include "DayView.h"
- #include "Entry.h"
- #include "Info.h"
-
- #include <Xm/DrawingA.h>
-
- static int count;
- static Arg args[10];
-
- OverviewDay::OverviewDay(char *name, Widget parent, VCal *o)
- : VkComponent(name)
- {
- XGCValues gcv;
-
- owner = o;
-
- day = month = year = 0;
- today = False;
- start = stop = 0;
-
- count = 0;
- XtSetArg(args[count], XmNbackground, owner->normalColor()); count++;
- XtSetArg(args[count], XmNborderColor, owner->nonHighlightColor()); count++;
- _baseWidget = XmCreateDrawingArea(parent, name, args, count);
- XtAddCallback(_baseWidget, XmNexposeCallback,
- OverviewDay::area_expose, (XtPointer) this);
- XtAddCallback(_baseWidget, XmNinputCallback,
- OverviewDay::area_input, (XtPointer) this);
-
- gcv.foreground = owner->foregroundColor();
- gcv.background = owner->normalColor();
- gcLabel = XtGetGC(_baseWidget, GCForeground | GCBackground, &gcv);
- gcv.foreground = owner->foregroundColor();
- gcv.background = owner->annotateColor();
- gcv.stipple = owner->getTile();
- gcv.fill_style = FillOpaqueStippled;
- gcAnnotate = XtGetGC(_baseWidget,
- GCForeground | GCBackground | GCStipple | GCFillStyle,
- &gcv);
- }
-
- OverviewDay::~OverviewDay()
- {
- XtRemoveCallback(_baseWidget, XmNexposeCallback,
- OverviewDay::area_expose, (XtPointer) this);
- XtRemoveCallback(_baseWidget, XmNinputCallback,
- OverviewDay::area_input, (XtPointer) this);
- XtReleaseGC(_baseWidget, gcLabel);
- XtReleaseGC(_baseWidget, gcAnnotate);
- }
-
- const char *
- OverviewDay::className()
- {
- return "OverviewDay";
- }
-
- /**********************************************************************/
-
- void
- OverviewDay::setDate(int d, int m, int y, Boolean t, int s1, int s2)
- {
- day = d;
- month = m;
- year = y;
- today = t;
- start = s1;
- stop = s2;
- display();
- }
-
- /**********************************************************************/
-
- void
- OverviewDay::display()
- {
- char str[256];
- XmString xs;
- MemoryInfo *info;
- Entry *entry;
- RepeatingEntry *rentry;
-
- if (XtWindow(_baseWidget)) {
- count = 0;
- XtSetArg(args[count], XmNwidth, &width); count++;
- XtSetArg(args[count], XmNheight, &height); count++;
- XtGetValues(_baseWidget, args, count);
- XClearWindow(XtDisplay(_baseWidget), XtWindow(_baseWidget));
- if (day && month && year) {
- count = 0;
- if (today) {
- XtSetArg(args[count], XmNborderColor,
- owner->foregroundColor()); count++;
- } else {
- XtSetArg(args[count], XmNborderColor,
- owner->nonHighlightColor()); count++;
- }
- XtSetValues(_baseWidget, args, count);
- info = owner->findDateInfo(day, month, year);
- if (info) {
- info->rewind();
- while (entry = info->nextEntry()) {
- displayEntry(entry);
- }
- }
- rentry = owner->getRepeatingEntries();
- while (rentry->next()) {
- rentry = rentry->next();
- if (rentry->repeatApplies(day, month, year)) {
- displayEntry(rentry);
- }
- }
-
- sprintf(str, "%d", day);
- xs = XmStringCreateSimple(str);
- XmStringDrawImage(XtDisplay(_baseWidget), XtWindow(_baseWidget),
- owner->getLabelFont(), xs, gcLabel,
- 0, 2, XmStringWidth(owner->getLabelFont(), xs)+8,
- XmALIGNMENT_CENTER, XmSTRING_DIRECTION_R_TO_L, NULL);
- } else {
- count = 0;
- XtSetArg(args[count], XmNborderColor,
- owner->normalColor()); count++;
- XtSetValues(_baseWidget, args, count);
- }
- }
- }
-
- void
- OverviewDay::displayEntry(Entry *entry)
- {
- int y, h;
- float total;
-
- total = stop-start;
- y = (int) (0.5+height*(entry->start()-start)/total);
- h = (int) (0.5+height*entry->length()/total);
- if (h > 3) {
- h -= 1;
- }
- XFillRectangle(XtDisplay(_baseWidget), XtWindow(_baseWidget),
- gcAnnotate,
- 0, y, width, h);
- }
-
- void
- OverviewDay::select()
- {
- int nowDay, nowMonth, nowYear;
-
- if (day) {
- owner->selectDay(day, month, year);
- owner->getToday(&nowDay, &nowMonth, &nowYear);
- if (day == nowDay && month == nowMonth && year == nowYear) {
- owner->getDayView()->scrollToCurrentTime();
- } else {
- owner->getDayView()->scrollToBeginning();
- }
- }
- }
-
- /**********************************************************************/
-
- void
- OverviewDay::area_expose(Widget, XtPointer client_data, XtPointer)
- {
- OverviewDay *obj = (OverviewDay *) client_data;
-
- obj->display();
- }
-
- void
- OverviewDay::area_input(Widget, XtPointer client_data, XtPointer call_data)
- {
- OverviewDay *obj = (OverviewDay *) client_data;
- XmDrawingAreaCallbackStruct *cb = (XmDrawingAreaCallbackStruct *) call_data;
-
- if (cb->event && cb->event->type == ButtonPress &&
- cb->event->xbutton.button == Button1) {
- obj->select();
- }
- }
-